package com.fare.taluo.core.domain.crawl.statistics;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;

import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.core.domain.BaseEntity;
import com.fare.taluo.core.domain.crawl.TaskQueueLogEntityRepository;

@javax.persistence.Table(name="STATISTICS_TOTAL_DETAIL")
@javax.persistence.Entity
public class StatisticsTotalDetailEntity extends BaseEntity<StatisticsTotalDetailEntity> implements Entity{
	private static final long serialVersionUID = 7924245433935886065L;

	/*
	 * sys_guid() as testid,
s.id,
s.grab_channel,
s.flight_date,s.grad_date,s.from_city,
s.from_city_name,s.to_city,s.to_city_name,
s.min_time,s.max_time,s.success_num,s.fail_num,s.status,s.byte_length,s.source_data_size
	*/
	
	@javax.persistence.Id
	@javax.persistence.Column(name="id", length=32)
	@javax.persistence.GeneratedValue(generator="system-uuid")
	@org.hibernate.annotations.GenericGenerator(name="system-uuid", strategy="uuid")
	private String id;
	@Column(name = "GRAB_CHANNEL")
	private String grabchannel;
	@Column(name = "FLIGHT_DATE")
	private String flightdate;
	@Column(name = "CREATE_DATE")
	private String createdate;
	@Column(name = "GRAD_DATE")
	private String grabdate;
	@Column(name ="FROM_CITY")
	private String fromCity;
	@Column(name ="FROM_CITY_NAME")
	private String fromCityName;
	@Column(name ="TO_CITY")
	private String toCity;
	@Column(name ="TO_CITY_NAME")
	private String toCityName;

	@Column(name = "SUCCESS_NUM")
	private Long successNum;
	@Column(name = "FAIL_NUM")
	private Long failNum;
	
	@Column(name = "start_time")
	private Date startTime;
	
	@Column(name = "end_time")
	private Date endTime;
//	@Column(name="ACTUAL_NUM")
//	private Long actualNum;
//	
	//各种失败原因的状态   -2表示      抓取失败
	//			   -3表示     解析失败  
	//			   -4表示    其他失败
	//             -10表示  未定义失败
	@Column(name="STATUS")
	private Long status;
	
	@Column(name="grab_channel_id")
	private Long grabchannelID;
	
	@Column(name="SOURCE_DATA_SIZE")
	private Long sourceDataSize;
	
	@Column(name="byte_length")
	private Long allbyteLength;
	
//	
//	@Column(name="waiting")
//	private Long waiting;
//	
//	@Column(name="starting")
//	private long starting;

	@Column(name="min_time")
	private long minTime;
	
	@Column(name="max_time")
	private long maxTime;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getGrabchannel() {
		return grabchannel;
	}

	public void setGrabchannel(String grabchannel) {
		this.grabchannel = grabchannel;
	}

	public String getFlightdate() {
		return flightdate;
	}
	
	public String getCreatedate() {
		return createdate;
	}

	public void setCreatedate(String createdate) {
		this.createdate = createdate;
	}

	public void setFlightdate(String flightdate) {
		this.flightdate = flightdate;
	}

	public String getGrabdate() {
		return grabdate;
	}

	public void setGrabdate(String grabdate) {
		this.grabdate = grabdate;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}


	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Long getSuccessNum() {
		return successNum;
	}

	public void setSuccessNum(Long successNum) {
		this.successNum = successNum;
	}

	public Long getFailNum() {
		return failNum;
	}

	public void setFailNum(Long failNum) {
		this.failNum = failNum;
	}


	public Long getStatus() {
		return status;
	}

	public void setStatus(Long status) {
		this.status = status;
	}

	public Long getGrabchannelID() {
		return grabchannelID;
	}

	public void setGrabchannelID(Long grabchannelID) {
		this.grabchannelID = grabchannelID;
	}

	public Long getSourceDataSize() {
		return sourceDataSize;
	}

	public void setSourceDataSize(Long sourceDataSize) {
		this.sourceDataSize = sourceDataSize;
	}

	public Long getAllbyteLength() {
		return allbyteLength;
	}

	public void setAllbyteLength(Long allbyteLength) {
		this.allbyteLength = allbyteLength;
	}



	public long getMinTime() {
		return minTime;
	}

	public void setMinTime(long minTime) {
		this.minTime = minTime;
	}

	public long getMaxTime() {
		return maxTime;
	}

	public void setMaxTime(long maxTime) {
		this.maxTime = maxTime;
	}

	//private static TaskQueueLogEntityRepository repository = InstanceFactory.getInstance(TaskQueueLogEntityRepository.class);
	private static TaskQueueLogEntityRepository getTaskQueueLogEntityRepository(){
		return InstanceFactory.getInstance(TaskQueueLogEntityRepository.class);
	}
	//引擎统计 total详细信息查询
			
			public List<StatisticsTotalDetailEntity> getTotalAllByFromAndTo(String grabdate,String grabchannelID,String fromCity,String toCity){
				return getTaskQueueLogEntityRepository().getTotalAllByFromAndTo(grabdate,grabchannelID,fromCity,toCity);
			}
			//引擎统计 total详细信息查询  
			public int getTotalCountByFromAndTo(Date grabdate,String grabchannelID,String fromCity, String toCity){
				return getTaskQueueLogEntityRepository().getTotalCountByFromAndTo(grabdate, grabchannelID,fromCity ,toCity);
			}
//	

			@Override
			public boolean isNew() {
				return getId() == null ;
			}

			@Override
			public boolean existed() {
				if (isNew()) {
					return false;
				}
				return getRepository().exists(getClass(), getId());
			}

			@Override
			public boolean notExisted() {
				return ! existed();
			}
			
			@Override
			public boolean existed(String propertyName, Object propertyValue) {
				List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
				return !(entities.isEmpty());
			}
}


